package com.giscloud.generator.service;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.giscloud.generator.dao.DatabaseDao;
import com.giscloud.generator.entity.DatabaseEntity;
import com.giscloud.generator.utils.PageUtils;
import com.giscloud.generator.utils.Query;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @Author:giscloud
 * @Description:
 * @Date: 14:47 2019/11/21
 * @Modified By:
 */
@Service
public class DatabaseService {
    @Autowired
    private DatabaseDao databaseDao;

    public PageUtils list(Query query){
        Page<?> page = PageHelper.startPage(query.getPage(), query.getLimit());
        List<DatabaseEntity> list = databaseDao.listDatabases(query);
        return new PageUtils(list, (int)page.getTotal(), query.getLimit(), query.getPage());
    }

    public List<Map<String, Object>> selectDatabases1(){
        return databaseDao.selectDatabases1();
    }

    public List<Map<String, Object>> selectDatabases(){
        return databaseDao.selectDatabases();
    }

    public int insert(DatabaseEntity databaseEntity){
        return databaseDao.insert(databaseEntity);
    }

    public int update(DatabaseEntity databaseEntity){
        return databaseDao.update(databaseEntity);
    }

    public int delete(long[] ids){
        return databaseDao.delete(ids);
    }
}
